package com.luyu.hystrixdemo;

import okhttp3.*;
import okhttp3.logging.HttpLoggingInterceptor;

import java.time.Duration;
import java.util.HashMap;

public class OkHttpExample {
    public static void main(String[] args) {
        // 创建日志拦截器
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); // 设置日志级别为 BODY

        // 创建OkHttpClient实例
        OkHttpClient client = new OkHttpClient.Builder()
                .callTimeout(Duration.ofSeconds(120))
                .connectTimeout(Duration.ofSeconds(120))
                .addInterceptor(loggingInterceptor)
                .build();

        MediaType JSON = MediaType.parse("application/json; charset=utf-8");
        HashMap<String,String> map=new HashMap<>();
        String data="{\n" +
                "    \"address\": \"0x2D7992442c1F4341BF8AEbc48c29129E68D81679\",\n" +
                "    \"visitorId\": \"c75f7378204da785c84a1cf9fcc27612\",\n" +
                "    \"recaptchaToken\": \"03AFcWeA47A_TqKOvUdQec33zKZyEnH3wUTsr-icR3LusHgAyYTd3orSLTWM7oszAU3lln0zqQeb5qZuCHlxF2wnpj1yR2ZhjVqW1hA7PSl1hwbwO-vaFXx_nvO53M9_3GLy_Zflw3XH6tpvTvQkOKhVKv5Zsq5Rq7Vj-IoTk510zldI9OOSSWo87vJqdH1aGbFLIi-XMlctlSVuBDqx6LR0ymQJKHLw7IlJQ2fKQnfxPmwW8iDCxwEALI3nLlcBirDJCrC8of70RCTNn_ZghDl_lJRRxF1IM7D4lz6qOrh3U1WW2bx1IDBG1M8dZtwNb66GMWdMeM7gDRMEx-7oUqlQ6GovqSUpSg0lud_ol5cGWuvphq_AVuZazr0fcMnCknrJcS9RQfA01dud98M8JTDbOAjouGGR0T44-9BdKBImr47eEnlgMhiD-bcN2VJVguK7L3mYaYo4ELC8m7KbbAm_B0ZrnAqTIeOGA4appRWRxPQ4Lots1SnAWtE01Qh1H3CkwqFT4a_jaDSBCDjcNX6P0Y2JPH-4Tgo4vl4Ps_Mti2JZXxd5jg0O1YYfwmi3kWg5cHxmktnd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gXEyyMoDEa_afyspvKIr7yiMrswzw59IqVXFyzpJXVCKZ-s8CGVEIyem6uUcs55OvFMw4NmSzGBzHk8R9J8lLNgUxomTkHVkYiFoL6YArC59wOmWJf_nQObug86KZoZusRUUTcCQxcQ34Jgc4Hdki_vLSiaP__RqNneP5T0lVrBDCrb1gvAJrR7lfi8HrjdMoBsk_Vm5Rs_icw8id8SKzfqMWwfIHoNfansc58CkiNWo8rAgasTe0lOXA-AW9Vm6JGiQqOG8iCZbsX3cozUqiTuzbQycSXsdwjA9SJAPut5Nt0nuIWUunh9C61eIHuqW8sRMHh_D-0Fl_ryB3oZ6FvHQxOmeOKeFyQ5Nb_-4mMkysVcGMbrm7uYod8SFe9nrzbE1qxVir1KwcUzwycPltVZo6L5e0FqLYfD9EPL5JObFzlx-kWvIPas_WtK7dR0aMZHqE65wabz2PNhbUuiVWXYCT54JEAy20LPdKFh70xw5852w0gUoqq2mTmZOqYvq7jo1JYZEVMIuH6FlxzSUa6nT6XH4f1tlzizTC95Y-iUxWyoR9ELhC2LJbk1-FOr6nlgllX74py\"\n" +
                "}";

        // 构建请求
        Request request = new Request.Builder()
                .post(RequestBody.create(data,JSON))
                .url("https://testnet.monad.xyz/api/claim")// 替换为你要请求的URL
                .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36")  // 设置请求头
                .addHeader("content-type","application/json")
                .addHeader("Accept-Language", "en-US,en;q=0.9")
                .addHeader("Referer", "https://www.google.com/")
                .addHeader("Connection", "keep-alive")
                .build();

        try {
            // 发送请求并获取响应
            Response response = client.newCall(request).execute();
            // 检查响应是否成功
            if (response.isSuccessful()) {
                // 打印响应体
                System.out.println(response.body().string());
            } else {
                System.out.println("Request failed with code: " + response.code());
            }
        } catch (Exception e) {

            map.put(e.getMessage(),e.getMessage());
            e.printStackTrace();
        }
    }
}